﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Diagnostics;

using NewPanda.ViewModel;
using P2PLib.Client;
using P2PLib.Client.Command;
using P2PLib.Client.ViewModel;
using NewPanda.Configure;

namespace NewPanda
{
    /// <summary>
    /// FileSharePanel.xaml 的交互逻辑
    /// </summary>
    public partial class FileSharePanel : UserControl
    {
        private Client client = App.Client;

        public FileSharePanel()
        {
            InitializeComponent();
            this.DataContext = client;

        }

        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            string keyword = this.SearchTextBox.Text;
            client.SearchFileByName(keyword);
        }

        private void ResultListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            SearchResultViewModel sr = (SearchResultViewModel)this.ResultListView.SelectedItem;

            AddNewTaskWindow w = new AddNewTaskWindow();
            w.DirTextBox.Text = App.dir + "\\" + RedPandaConfig.DownloadFolderName;
            w.NameTextBox.Text = sr.File.FileName;

            w.ShowDialog();

            DownloadTaskViewModel dtvm = new DownloadTaskViewModel(sr,w.DirTextBox.Text,w.NameTextBox.Text);
            this.client.Tasks.Add(dtvm);
            dtvm.Start();
        }
    }
}
